package com.srit.recipes.common.exception;


import com.srit.recipes.common.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import static com.srit.recipes.common.response.Response.error;

@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalException {

    @ExceptionHandler(RecipesException.class)
    public Response runHandlerTbas(RecipesException e){
        e.printStackTrace();
        return error(e.getMessage(),400);
    }

    @ExceptionHandler(Exception.class)
    public Response runHandler(Exception e){
        e.printStackTrace();
        return error(e.getMessage());
    }
}
